package com.csyaonie.android;

import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.csyaonie.android.utils.ToastUtil;

public class ToastActivity extends AppCompatActivity {

    private Button toast1;

    private Button toast2;

    private Button toast3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_toast);
        toast1=findViewById(R.id.toast1);
        toast2=findViewById(R.id.toast2);
        toast3=findViewById(R.id.toast3);
        toast1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast toast= Toast.makeText(getApplicationContext(),"hello",Toast.LENGTH_LONG);
                toast.setGravity(Gravity.CENTER,0,0);
                toast.show();
            }
        });
        toast2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast toast = new Toast(getApplicationContext());
                LayoutInflater inflater= LayoutInflater.from(ToastActivity.this);
                View view = inflater.inflate(R.layout.toast_view_item,null);
                TextView textView=view.findViewById(R.id.toasttv);
                textView.setText("hello world");
                toast.setDuration(Toast.LENGTH_LONG);
                toast.setView(view);
                toast.show();
            }
        });
        toast3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtil.showLong(ToastActivity.this,"hehe");
            }
        });

    }
}